
//快乐数判断
class Solution {
public:

    int getNext(int n){
        int x,y=0;
        while(n){
            x=n%10;
            y+=x*x;
            n=n/10;
        }
        return y;
    }


    bool isHappy(int n) {
        int p=n,q=n;
        while(q!=1){
            p=getNext(p);
            q=getNext(getNext(q));
            if(p==q&&p!=1) return false;
        }
        return true;
    }
};